#Server Makefile

include ../Engine/Makefile
include ../MakefileShared

LOCAL_INCLUDE_DIRS= $(LIB_INCLUDES) . ../Engine/ ../Engine/Networking ../Engine/Utilities

LOCAL_LFLAGS=$(LFLAGS) $(LOCAL_INCLUDE_DIRS:%=-I%)

LOCAL_LIBS= $(LIB_LIBS:%=-L%) -Wl,-rpath,. -L/lib/ -lrt -lpthread -L$(EXEC_PATH) -lsfml-network -lsfml-system -llua -lluabindd -lpugixml

LOCAL_FLAGS=$(CFLAGS) $(LOCAL_INCLUDE_DIRS:%=-I%) -MMD -MP -MF

SOURCES=ClientCollection.cpp \
    Client.cpp \
    LoadingClientCollection.cpp \
    Server.cpp \
    NetworkHandler.cpp \
    main.cpp \
    ServerScriptEngine.cpp \
    Objects/Character.cpp \
    Objects/Player.cpp \
    Objects/PlayerManager.cpp \
    Objects/ServerEntityManager.cpp \
    Objects/ServerRegion.cpp \
    Objects/ServerRegionManager.cpp \
    $(ROOT_SOURCES:%=../Engine/%) \
    $(OBJECT_SOURCES:%=../Engine/%) \
    $(NETWORK_SOURCES:%=../Engine/%) \
    $(SCRIPTING_SOURCES:%=../Engine/%) \
    $(CONTENT_SOURCES:%=../Engine/%) \
    $(UTILITY_SOURCES:%=../Engine/%)

OBJECTS=$(SOURCES:.cpp=.o)

.PHONY: all server clean
all: cleanexec compile

compile: $(OBJECTS)
	@echo ""
	@echo "Creating server executable"
	$(CC) -o $(EXEC_PATH)/server $(OBJECTS) $(LOCAL_LIBS)

server: $(OBJECTS)

$(OBJECTS): %.o: %.cpp
	@echo ""
	@echo "Compiling $@"
	$(RM) $@.d
	$(CC) $(LOCAL_FLAGS) -MMD -MP -MF $@.d  -o $@ $<	

cleanexec:
	@echo ""
	@echo "Cleaning Server"
	$(RM) $(EXEC_PATH)/server

clean: cleanexec
	$(RM) $(OBJECTS)
	$(RM) $(OBJECTS:.o=.o.d)
